<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    const obj = {
      name: 'why',
      age: 18,
      height: 1.88
    }

    // 1.创建一个Proxy对象
    const objProxy = new Proxy(obj, {
      set: function (target, key, value) {
        console.log(`监听:监听${key}的设置`)
        target[key] = value
      },
      get: function (target, key) {
        console.log(`监听:监听${key}的获取`)
        return target[key]
      },

    })

    // 2.对obj的所有操作,应该去操作objProxy
    console.log(objProxy.name)
    objProxy.name = 'kobe'
    console.log(objProxy.name)

    objProxy.address = "广州市"
    console.log(objProxy.address)

  </script>
</body>

</html>